Extract & Scripting Interface

Related example scripts: Extract-and-fill.vbs, Extract-2-file.vbs, Get-Exchange-Rate.vbs

All extracted data can be send to your code via the Scripting Interface.
This gives you all the power of Windows scripting to process the extract values further or simply save them to a file. Remember, the Scripting Interface can be used with ANY Windows programming language!

The iimGetLastMessage command to returns the extracted text if you used the EXTRACT command within the macro.

The extracted text is returned as a string. Different values are separated by [EXTRACT] (Example: "Text to be extracted
[EXTRACT]Salary: 33,000.00 per year[EXTRACT]...")

Note 1: Do not use the SAVEAS TYPE=EXTRACT command if you want to return the extraction result to the Scripting Interface.

Note 2: If you extract a complete table, the data is separated by "#NEXT#" and each line ends with "#NEWLINE#". To convert this to the usual CSV format, please use the VBS "Replace" command (or its equivalent in another programming language):
s = Replace(s, "#NEWLINE#", """" + vbCrLf + """")
s = Replace(s, "#NEXT#", """"+ "," + """")


Example 1: (Split the returned EXTRACT string)

Dim data as String
Dim s as String
Dim ExchangeRate '<=this is the array that holds the different extract values after using 
split
iplay = iim1.iimPlay("wsh-extract")   [Return value: <0: Error, 1: Normal completion, 2: Text extracted]
If iplay = 2 Then 
   data = iim1.iimGetLastMessage() 'copy the result of all EXTRACT statements to the data string 
    ExchangeRate= Split(data, "[EXTRACT]")
    s = "One US$ costs " + ExchangeRate(0) + " EURO or " + ExchangeRate(1) + " British Pounds (GBP)"
    MsgBox s
End If


Example 2: (keyword search)

We want to find out if the word "iopus" exists on a web page. If yes, print the page.
To search the web page, create a mysearch macro:


VERSION BUILD=3301125
'The keyword *is* the data extraction anchor!
EXTRACT POS=1 ELEM=0 ATTR=
*iopus   

To print the web page, create print_this macro:

VERSION BUILD=3301125
PRINT 
   

Use the following Windows Script to control the macros:

set iim1= CreateObject ("iimwsh.iim")
iret = iim1.iimInit()
iplay = iim1.iimPlay("
mysearch")
extracted_text = iim1.iimGetLastMessage()
'test if keyword appeared on website. 
'The keyword *is* the data extraction anchor!
If 
iplay = 2 Then 
   if 
instr (extracted_text, "#EANF#") > 0 then
          MsgBox ("Sorry, keyword not found")
   else
         iplay = iim1.iimPlay("
print_this")
   End If
End if
If iplay < 0 Then
       MsgBox "Error!"
End If
   


More Examples:

Internet Macros comes with several example scripts that demonstrate the EXTRACT command:

·   extract-2-file.vbs
·   extract-and-fill.vbs
·   get-exchange-rate.vbs

The scripts are found in the "Examples\Windows Scripting Host" directory. More example scripts and test pages are available at http://www.iOpus.com/iim/demo